﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Administrator_HinhAnh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.FileUpload1.HasFile && Request.QueryString["ID"]!=null)
            {
                string type = FileUpload1.FileName.Substring(FileUpload1.FileName.Length - 3, 3);
                HinhAnhDA hda = new HinhAnhDA();
                int ten = RandomNumber();
                string pat = Server.MapPath("~/Image/SanPham/" + ten.ToString() + "." + type);
                FileUpload1.SaveAs(pat);
                hda.insert(Request.QueryString["ID"], "~/Image/SanPham/" + ten.ToString() + "." + type);
                Response.Redirect(Request.RawUrl);
            }
        }
        catch (Exception ex)
        {

            throw new Exception("Lỗi không upload được ảnh" + ex.Message);
        }
    }
    private int RandomNumber()
    {
        Random random = new Random();
        return random.Next(1, 1000000000);
    }
}